import React, { Component } from 'react'
import axios from 'axios'
import Top from './Top/index'
import Main from './Main/index'

class Home extends Component {

    state = {
        list: [],
        i: 0
    }

    componentDidMount() {
        axios.get('/api/list').then((res) => {
            this.setState({
                list: res.data
            })
        })
    }

    clickBtn = (index) => {
        this.setState({
            i: index
        })
    }

    render() { 
        let { list, i } = this.state
        return (
            <div>
                <Top list={list} i={i} clickBtn={this.clickBtn} />
                <Main list={list} i={i} />
            </div>
        )
    }
}
 
export default Home;